package arena;

import java.util.HashMap;

import com.jme.input.ChaseCamera;
import com.jme.input.thirdperson.ThirdPersonMouseLook;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;

public class Cam {
	private Camera 		camera = null;
	private ChaseCamera chaser = null;
	private Node	    target = null;
	
	public Cam(Renderer r, DisplaySystem d, Node target)
	{
		camera = r.getCamera();
		
		camera.setFrustumPerspective( 45.0f, (float) d.getWidth() / (float) d.getHeight(), 1, 1000 );
        camera.setParallelProjection( false );
        camera.update();
		
		camera.lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
		camera.normalize();
		camera.setAxes(new Vector3f(0, 0, -1), new Vector3f(0, 1, 0), new Vector3f(1, 0, 0));
		camera.update();
		
		this.target=target;
		buildChaseCamera();
	}
	
	private void buildChaseCamera() {
        Vector3f targetOffset = new Vector3f();
        targetOffset.y=1.0f;
        HashMap<String, Object> props = new HashMap<String, Object>();
        props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "90");
        props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "90");
        props.put(ThirdPersonMouseLook.PROP_MAXASCENT,  "" 
        		                                        + (90 * FastMath.DEG_TO_RAD));
        props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(45 * FastMath.DEG_TO_RAD,
        															  0,
        															 45 * FastMath.DEG_TO_RAD));
        props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
        
        chaser = new ChaseCamera(camera, target, props);
        chaser.setMaxDistance(6);
        chaser.setMinDistance(2);
        chaser.clearActions();
        chaser.setTarget(target);
        chaser.setStayBehindTarget(true);
        chaser.update(0.0f);
    }
	
	public Camera getCamera()
	{
		return camera; 
	}
	
	public ChaseCamera getChaser()
	{
		return chaser;
	}
}
